define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'work/index/index',
                    add_url: 'work/index/add',
                    edit_url: 'work/index/edit',
                    del_url: 'work/index/del',
                    multi_url: 'work/index/multi',
                    table: 'work',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'sno', title: __('Sno')},
                        {field: 'category_name', title: __('Cid')},
                        {field: 'pcategory_name', title: __('Pid')},
                        {field: 'title', title: __('Title')},
                        {field: 'cover', title: __('Cover'),formatter:Table.api.formatter.image},
                        {field: 'file', title: __('File'),formatter:Table.api.formatter.url},
                        {field: 'video', title: __('Video'),formatter:Table.api.formatter.url},
                        // {field: 'summary', title: __('Summary')},
                        {field: 'download', title: __('Download')},
                        {field: 'store', title: __('Store')},
                        {field: 'view', title: __('View')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'format', title: __('Format')},
                        // {field: 'size', title: __('Size'), operate:'BETWEEN'},
                        {field: 'creator_text', title: __('Creator')},
                        // {field: 'updator', title: __('Updator')},
                        // {field: 'tags', title: __('Tags')},
                        {field: 'status', title: __('Status'), visible:false, searchList: {"1":__('Status 1')}},
                        {field: 'status_text', title: __('Status'), operate:false},
                        // {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'utime', title: __('Utime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            $('input[name="row[pid]"]').data('params',function (obj) {
                return {custom:{pid:$('input[name="row[cid]"]').val()}};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});